﻿package core.drawing
{
    import core.enum.*;
    import flash.events.*;

    final public class PencilTool extends ShapeTool
    {
        var a:int;
        var r:int;
        var g:int;
        var b:int;
        var cx:int;
        var cy:int;
        var sx:int;
        var sy:int;
        var n:int;

        public function PencilTool(param1:Tuyitu)
        {
            super(param1, ToolType.Pencil);
            ctrl = ToolType.Picker;
            return;
        }// end function

        override public function MouseDown(event:MouseEvent) : void
        {
            if (!type.attitude.locked)
            {
                this.UpdateReferences();
                this.Prepare(Action.PencilTool, layer.SetBitmapEditMode(options.opacity, canvas.clip));
                options.color = ed.toolbar.GetColor(1, layer.editMask);
                this.r = options.color >>> 16 & 255;
                this.g = options.color >>> 8 & 255;
                this.b = options.color & 255;
                if (!event.shiftKey)
                {
                    var _loc_2:int = -1;
                    y = -1;
                    x = _loc_2;
                }
                this.MouseDrag(null);
            }
            return;
        }// end function

        override public function DrawShape(SetBitmapEditMode:int, SetBitmapEditMode:int) : void
        {
            this.n = -1;
            this.sy = SetBitmapEditMode - int(shape.height * 0.5);
            this.cy = this.sy + shape.height;
            while (this.sy < this.cy)
            {
                
                this.sx = SetBitmapEditMode - int(shape.width * 0.5);
                this.cx = this.sx + shape.width;
                while (this.sx < this.cx)
                {
                    
                    this.a = selection != null ? (selection.Max(this.sx + offset.x, this.sy + offset.y)) : (255);
                    var _loc_3:String = this;
                    _loc_3.n = this.n + 1;
                    if (shape.data[++this.n] > 64 && target.rect.contains(this.sx, this.sy))
                    {
                        target.setPixel32(this.sx, this.sy, this.a << 24 | this.r << 16 | this.g << 8 | this.b);
                    }
                    var _loc_3:String = this;
                    var _loc_4:* = this.sx + 1;
                    _loc_3.sx = _loc_4;
                }
                var _loc_3:String = this;
                var _loc_4:* = this.sy + 1;
                _loc_3.sy = _loc_4;
            }
            return;
        }// end function

    }
}
